﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tools;
using 纺织贸易管理系统;

namespace BLL
{
  public   class CheckStockBLL
    {
        public static bool CheckStock(List<danjumingxitable> mingxis)
        {
            try
            {
                var db = Connect.GetSugar();
                var listlots = new List<string>();
                foreach (var mingxi in mingxis)
                {
                    if (db.Queryable<StockTable>().Where(x => x.CustomName == mingxi.CustomName && x.GH == mingxi.ganghao).Count() > 0)
                    {
                        listlots.Add(mingxi.ganghao);
                    }
                }
                string message = string.Empty;
                if (listlots.Count > 0)
                {
                    foreach (var lot in listlots)
                    {
                        message += lot + ",\r\n";
                    }
                    return ShowMessageBox.ShowAskBox("该客户   "+mingxis[0].CustomName +"    的这些缸号\r\n" + message + "库存中已经存在,\r\n是否继续执行操作？") == System.Windows.Forms.DialogResult.Yes ? true : false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                ShowMessageBox.ShowErrorBox("检查是否重复库存的时候发生了错误！" + ex.Message);
                return false;
            }
        }
        public static bool Checkinventorys(List<danjumingxitable> mingxis,string stockname)
        {
            foreach(var item in mingxis)
            {
              var  stock = Connect.dbcontext.Queryable<StockTable>().First(x => x.CKMC == stockname && x.orderNum == item.OrderNum && x.YS == item.yanse &&
                   x.kuanhao == item.kuanhao && x.GH == item.ganghao && x.CustomName == item.CustomName && x.PM == item.pingming&&x.RKDH==item.danhao);
                if(stock==null)
                {
                    return false;
                }
            }
            return true;
        }
    }
}
